package Shopfashion;


import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ThemSanPhamMoi
 */
@WebServlet("/Them_San_Pham_Moi")
public class ThemSanPhamMoi extends HttpServlet {
	
	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		  // TODO Auto-generated method stub
		response.setContentType("text/html;charset=UTF-8");
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();

        String model = request.getParameter("model");
        String mausac =request.getParameter("mausac");
        String size = request.getParameter("size");
        String chatlieu =request.getParameter("chatlieu");
        Double dongia = Double.parseDouble(request.getParameter("dongia"));
        Double vongnguc = Double.parseDouble(request.getParameter("vongnguc"));
        Double vongeo =Double.parseDouble(request.getParameter("vongeo"));
        Double vongmong =Double.parseDouble(request.getParameter("vongmong"));
        String hinhanh =request.getParameter("hinhsp");
        String ngaynhap =request.getParameter("ngaynhap");
        String mota =request.getParameter("mota");

        SanPham sp = new SanPham(model, mausac, size, chatlieu, dongia, vongnguc, vongeo, vongmong,  hinhanh, ngaynhap, mota);
        ConnectDB db= new ConnectDB();
            
            	try {
					if(db.insertNew(sp))
						response.sendRedirect("San_Pham.jsp");
					else
						response.sendRedirect("Ero.jsp");
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

	}

	
	public boolean checkDigit(String s)
	{
		for (int i = 0; i < s.length(); i++) 
            if (Character.isLetter(s.charAt(i)))
                return false;
	    return true;
	}
	
}